const moment = require('moment');
module.exports = app => {
  const {INTEGER, DATE, BIGINT} = app.Sequelize;

  const OperationLog = app.model.define('operationLog', {
    id: {
      type: BIGINT,
      primaryKey: true,
      autoIncrement: true,
    },
    create_time: {
      type: DATE,
      get() {
        return moment(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
      }
    },
    update_time: {
      type: DATE,
      get() {
        return moment(this.getDataValue('update_time')).format('YYYY-MM-DD HH:mm:ss');
      }
    },
    target_id: BIGINT,
    target_type: INTEGER,
    type: INTEGER,
    user_id: BIGINT,
    times: INTEGER
  }, {
    tableName: 'hy_operation_log',
    timestamps: false,
  });

  OperationLog.associate = function() {
    app.model.OperationLog.belongsTo(app.model.User, {
      as: 'user',
      foreignKey: 'user_id',
      targetKey: 'user_id'
    })
  };

  return OperationLog;
};
